import 'package:flutter_ok/entity/user_info.dart';

class BaseResp<T> {
  int code;
  String msg;
  T data;

  BaseResp({this.code, this.msg, this.data});

  factory BaseResp.fromJson(json) {
    return BaseResp(
      code: json["code"],
      msg: json["msg"],
      data: asT<T>(json["data"]),
    );
  }

  bool isSuccess() {
    return code == 1;
  }

  bool isTokenError() {
    return code == 403;
  }

  static T asT<T>(json) {
    if (json == null) {
      return null;
    }
    if (T.toString() == "UserInfo") {
      return UserInfo.fromJson(json) as T;
    }
    return json as T;
  }
}
